<template>
  <div>
    <div class="news_container">
      <h1 class="news_title">{{ news.title }}</h1>
      <p class="news_add_time">
        <span>发表时间：{{ news.add_time | dateFormat }}</span>
        <span>点击：{{ news.click }}次</span>
      </p>
      <hr>
      <div class="news_content" v-html="news.content"></div>
    </div>
    <!-- 父组件向子组件传递值
      newsid是新闻的id,让子组件知道是获取哪一个新闻的评论
      classes是父组件所属的分类,告诉子组件调用后台接口时,后台应该取什么表的数据,'newsinfo' 表示这是一个新闻信息对象
     -->
    <comment :obj_id="id"></comment>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
import comment from "../../subcomponents/comment.vue"
export default {
  data() {
    return {
      id: this.$route.params.id,
      news: {}
    };
  },
  components:{
    comment
  },
  created() {
    this.get_news_info();
  },
  methods: {
    // 发送请求获取新闻详情
    get_news_info() {
      this.$http
        .get("api/getnews/" + this.id + "/")
        .then(result => {
          if (result.data.res === -1) {
            return Toast("新闻不存在");
          } else if (result.data.res === 0) {
            this.news = result.data.news[0];
          }
        });
    }
  }
};
</script>
<style lang="scss">
.news_container {
  padding: 0 5px;
  .news_title {
    font-size: 16px;
    color: red;
    text-align: center;
    margin: 10px 0;
  }
  .news_add_time {
    display: flex;
    justify-content: space-between;
    color: #226aff;
  }
  .news_content {
    img {
      width: 100%;
    }
    .article__title {
      font-size: 14px;
    }
    .article__author {
      height: 24px;
      position: relative;
      margin-top: 12px;
      .avatar {
        width: 24px;
        height: 24px;
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        margin: auto;
        .avatar__image,
        .avatar__mask {
          width: 100%;
          height: 100%;
          border-radius: 32px;
          position: absolute;
          top: 0;
          left: 0;
        }
      }
      .author-name {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 30px;
        margin: auto;
        font-size: 14px;
        color: #222;
        line-height: 24px;
        margin-left: 6px;
      }
      .article-info{
          position: absolute;
          right: 0;
          top: 0;
          bottom: 0;
          margin: auto;
          font-size: 12px;
          color:#999;
          line-height: 24px;
          .dot{
              display:inline-block;
              width: 2px;
              height: 2px;
              border-radius: 1px;
              background-color: #999;
              margin: 0 8px;
              vertical-align: middle;
          }
      }
    }
  }
}
</style>
